﻿using System;
using System.Linq;
using System.Web.UI.WebControls;
using Models;
using System.Data;


    public partial class TagList : AdminBase
    {
        
        private DataTable dc = new DataTable();
            protected void Page_Load(object sender, EventArgs e)
            {
                grdbind();
            }

            public void grdbind()
            {
                using (Entities bll = new Entities())
                {
                    var Bpl = bll.S_Goods.Where(x=>x.GIState==false).OrderBy(p=>p.GSort);
                    PagedDataSource pds = new PagedDataSource();
                    pds.DataSource = Bpl.ToList();
                    pds.AllowPaging = true;
                    AspNetPager1.RecordCount = Bpl.Count(); //记录总数；
                    pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;
                    pds.PageSize = AspNetPager1.PageSize;
                    this.rptList.DataSource = pds;
                     this.rptList.DataBind();
                }
            }

            protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
            {   //当页面页数改变时，执行这个方法；
                AspNetPager1.CurrentPageIndex = e.NewPageIndex;
                grdbind();
            }
    protected void rptList_ItemCommand(object source, RepeaterCommandEventArgs e)
            {
                int id = Convert.ToInt32(((Label)e.Item.FindControl("lb_id")).Text);
                Entities bll = new Entities();
                    S_Goods model = bll.S_Goods.First(p => p.GID == id);
                switch (e.CommandName.ToLower())
                {
                        case "lock":
                if (model.GIState == true)
                {
                    model.GIState = false;
                }
                else
                {
                    model.GIState = true;
                }
                break;
                }
                bll.SaveChanges();
                grdbind();
              
           }

    //改变状态点击事件
    public void change_Click(object sender, EventArgs e)
    {       
        Entities db = new Entities();
        LinkButton lb = (LinkButton)sender;
        if (lb.CommandName == "lock")
        {
            int _Id = Convert.ToInt32(lb.CommandArgument);
            var bll = db.S_Goods.SingleOrDefault(p => p.GID == _Id);
            if (bll != null)
            {
                if (bll.GIState == true)
                {
                    bll.GIState = false;
                }
                else
                {
                    bll.GIState = true;
                }
                db.SaveChanges();
            }               
        }
    }

    //获取状态
    public string getState(bool Sta)
    {
        string result = "";
        if (Sta == true)
        {
            result = "正常";
        }
        else
        {
            result = "<font color=red>锁定</font>";
        }
        return result;
    }

    //通过ID找到兑换券
    public static string GetCertifiNameById(string CodeId)
    {
        int id = int.Parse(CodeId);

        string result = "";
        //Entities db = new Entities();
        //try
        //{
        //    var info = db.S_CodeClass.FirstOrDefault(p => p.CodeCLassID == id);
        //    result = info.CCname;
        //}
        //catch
        //{
        //    result = "为空";
        //}
        return result;
    }
}
  
